package com.ymttest.business.data;

import java.io.IOException;
import java.util.List;

import org.apache.http.client.ClientProtocolException;

import com.shop2cn.iapi.agentproducts.parameter.GetProductListBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.parameter.UpdateStockAndPriceBean;
import com.shop2cn.iapi.agentproducts.service.GetProductListCall;
import com.shop2cn.iapi.agentproducts.service.UpdateStockAndPriceCall;
import com.ymt.core.tool.Logger;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;

public class AgentProductStg {
	public static List<ProductListDto>  getProductListDto(Integer mchid,Integer pageindex,Integer pagesize) throws ClientProtocolException, IOException {
		GetProductListCall getproductlistCall = new GetProductListCall();
		GetProductListBean getproductlistBean = AddAgentProductCallService.initGetProductListBean(mchid);
		getproductlistBean.setPageIndex(pageindex);
		getproductlistBean.setPageSize(pagesize);
		getproductlistCall.setData(getproductlistBean);
		getproductlistCall.callService();
		List<ProductListDto> productListDtoList = getproductlistCall.getProductList();
		return productListDtoList;
	}
	public static void updateStockAndPrice(Integer mchid,String pid,String sku,Integer stock,Double price) throws ClientProtocolException, IOException {
		UpdateStockAndPriceBean updatestockandpriceBean=new UpdateStockAndPriceBean();
		UpdateStockAndPriceCall updatestockandpriceCall=new UpdateStockAndPriceCall();
		updatestockandpriceBean.setUserId(mchid);
		updatestockandpriceBean.setSkuId(sku);
		updatestockandpriceBean.setSalePrice(price);
		updatestockandpriceBean.setRealStock(stock);
//		updatestockandpriceBean.setVirtualStock(300);
		updatestockandpriceCall.setData(updatestockandpriceBean);
		updatestockandpriceCall.callService();
	}
	public static void main(String[] args) throws ClientProtocolException, IOException {
		//批量更新商品的价格和库存 必须要有sku才行
//		Integer mchid=500003891;
//		AgentProductStg.getProductListDto(mchid,1,2002).forEach(p->{
//			p.getCatalogList().forEach(c->{
//				Logger.debug(p.getProductId()+","+c.getCatalogId()+","+c.getSku());
//				if(c.getSku()!=null&&c.getSku().length()>0) {
//					try {
//						AgentProductStg.updateStockAndPrice(mchid, p.getProductId(), c.getSku(), 999999, 1d);
//						TestDataManager.appendFileToLine("agentproductStg.txt", p.getProductId()+","+c.getCatalogId());
//					} catch (IOException e) {
//						e.printStackTrace();
//					}
//				}
//			});
//			
//		});
		
		//刷新token
//		TestDataManager.getLines("token1.dat").forEach(t1->{
//			String[] tdata = t1.split(",");
//			if(tdata.length>2) {
//				String token;
//				try {
//					token = AuthCallServiceV2.createToken(Integer.valueOf( tdata[1]), "goduserwxapp");
//					TestDataManager.appendFileToLine("token2.dat", token+","+tdata[1]+","+tdata[2]);
//				} catch (NumberFormatException | IOException e) {
//					e.printStackTrace();
//				}
//				
//			}
//		});
		GodMemberService.setCollectionMobile(500003891, false);
	}
	
}
